package juc.thread;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/03/07 08:31
 */

/**
 * Callable 和 Future
 */

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程间的协程，下面的数据需要上面的数据，
 * 那么就需要等待，怎么实现这个响应
 */
class CallableA implements Callable {
    @Override
    public Object call() {
        System.out.println(Thread.currentThread().getName());
        return "123";
    }
}

public class CreateThread2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableA callableA = new CallableA();
        FutureTask<String> future = new FutureTask<String>(callableA);
        new Thread(future, "A").start();
        System.out.println(future.get());
        Thread thread = new Thread(()->{
            System.out.println(123);
        },"A");
        ThreadLocal threadLocal = new ThreadLocal();
    }
}
